<template>
  <transition name="fade">
    <div v-if="visible" class="toast">
      {{ message }}
    </div>
  </transition>
</template>

<script>
export default {
  name: "Dialog",
  props: {
    message: {
      type: String,
      default: "",
    },
    duration: {
      type: Number,
      default: 3000, // 默认持续时间3秒
    },
  },
  data() {
    return {
      visible: false,
    };
  },
  methods: {
    show() {
      this.visible = true;
      setTimeout(() => {
        this.visible = false;
      }, this.duration);
    },
  },
  mounted() {
    this.show(); // 显示Toast消息
  },
};
</script>

<style scoped>
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 20px 30px;
  background: rgba(0, 0, 0, 0.8);
  font-size: 45px;
  color: white;
  border-radius: 10px;
  max-width: 70vw;
  font-family: "stc-medium";
  z-index: 1000; /* 确保Toast在页面其他元素之上 */
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active in <2.1.8 */ {
  opacity: 0;
}
</style>
